package com.zwj.design.behavior.observer.demo1.impl;

import com.zwj.design.behavior.observer.demo1.DisplayElement;
import com.zwj.design.behavior.observer.demo1.Observer;
import com.zwj.design.behavior.observer.demo1.Subject;

/**
 * 当前状态布告板
 *
 * @author 张文接
 * @version 1.0
 * @createTime 2024/3/16 22:15
 */
public class CurrentConditionsDisplay implements Observer, DisplayElement {
    /**
     * 温度
     */
    private float temperature;
    /**
     * 湿度
     */
    private float humidity;
    /**
     * 压强
     */
    private float pressure;
    /**
     * 天气信息数据源
     */
    private Subject weatherData;

    /**
     * 初始化布告板
     *
     * @param weatherData 天气信息数据源
     */
    public CurrentConditionsDisplay(Subject weatherData) {
        this.weatherData = weatherData;
        //注册到主题上
        weatherData.registerObserver(this);
    }

    @Override
    public void display() {
        System.err.println("当前温度：" + temperature + "℃，当前湿度与压强为：" + humidity + "%," + pressure);
    }

    @Override
    public void update(float temperature, float humidity, float pressure) {
        this.temperature = temperature;
        this.humidity = humidity;
        this.pressure = pressure;
    }
}
